package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/number-of-smooth-descent-periods-of-a-stock/
 * @create 2025/11/3 09:38
 * @since JDK17
 */

public class Solution03 {
    public long getDescentPeriods(int[] prices) {
        long ans = 0;
        int n = prices.length;
        for (int i = 0, j = 0; j < n; i = j) {
            j++;
            while (j < n && prices[j - 1] + 1 == prices[j]) {
                j++;
            }
            ans += (long) (j - i) * (j - i + 1) / 2;
        }

        return ans;
    }
}
